from multiprocessing import Process
from time import sleep
import os

class SubProcess(Process):
    def __init__(self, name):
        super().__init__()
        self.name = name

    def run(self):
        print(f'执行子进程pid:{os.getpid()}，父进程pid：{os.getppid()}======{self.name}')
        sleep(1)


if __name__ == '__main__':
    print('父进程开始')
    lst = []
    for i in range(3):
        p1 = SubProcess(name=f'sub-{i}')
        print('创建子进程。。。', p1.name)
        p1.start()
        lst.append(p1)

    for p in lst:
        p.join() # 阻塞主进程，等待p1执行结束

    print('主进程结束')
